package com.zkw.ss.listener;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * Created by Administrator on 2016/5/3 0003.
 */
public class CountLineListener implements HttpSessionListener {
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        ServletContext context=httpSessionEvent.getSession().getServletContext();
        Integer count=(Integer) context.getAttribute("count");
        System.out.println("sessionCreated"+count);
        if (count==null){
            count=1;
            context.setAttribute("count",count);
        }else {
            count++;
            context.setAttribute("count",count);
        }
    }

    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        ServletContext context=httpSessionEvent.getSession().getServletContext();
        Integer count=(Integer) context.getAttribute("count");
        count--;
        context.setAttribute("count",count);
        System.out.println("sessionDestroyed"+count);
    }
}
